package com.oauth.service.application.registry;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;

import com.oauth.logging.OAuthLogger;
import com.oauth.service.application.registry.beans.ApplicationInfoBean;

/**
 * Used by each application to register application info bean to global
 * registration service.
 * 
 * @author asanthan
 * 
 */
public class ApplicationRegistryService {

	private ApplicationInfoBean mApplicationInfoBean;

	private GlobalRegistryService<ApplicationInfoBean> mGlobalRegistryService;

	private OAuthLogger mLogger = OAuthLogger.getLogger(this.getClass());

	@PostConstruct
	public void register() {
		mLogger.info("Registering ...." + mApplicationInfoBean.getName());
		mGlobalRegistryService.registerApplication(mApplicationInfoBean);
	}

	/**
	 * @param pApplicationInfoBean
	 *            the applicationInfoBean to set
	 */
	@Autowired
	public void setApplicationInfoBean(ApplicationInfoBean pApplicationInfoBean) {
		mApplicationInfoBean = pApplicationInfoBean;
	}

	/**
	 * @param pApplicationRegistryService
	 *            the applicationRegistryService to set
	 */
	@Required
	public void setGlobalRegistryService(
			GlobalRegistryService<ApplicationInfoBean> pApplicationRegistryService) {
		mGlobalRegistryService = pApplicationRegistryService;
	}

}
